/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/best-time-to-buy-and-sell-stock
   @Language: C++
   @Datetime: 19-08-23 14:35
   */

class Solution {
public:
	int maxProfit(vector<int>& prices) {
		int p=0, mx=INT_MAX;
		for(int i=0; i<prices.size(); p=max(p,prices[i++]-mx))
			mx=min(mx,prices[i]);
		return p;
	}
};
